/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nokia.iap.ui.lib.prodcatalog;
import java.util.Vector;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;


/**
 *
 * @author zinin
 */
public class BasicRMS {

    private String rmsName = "prodcatalogRms";
    RecordStore rms;

    public void open() {
        try {
            rms = RecordStore.openRecordStore(rmsName, true);
        } catch (RecordStoreException rse) {
            rse.printStackTrace();
        }
    }

    public Vector get() {
        Vector result = new Vector();
        byte[] data = null;
        try {
            
            RecordEnumeration renum = rms.enumerateRecords(null, null, false);
            while (renum.hasNextElement()) {
                int index = renum.nextRecordId();
                data = rms.getRecord(index);
                String element = new String (data);
                result.addElement(element);
            }
//            data = rms.getRecord(0);
        } catch (RecordStoreException rse) {
            rse.printStackTrace();
        }
        return result;
    }

    public void set(byte[] data) {
        try {
            rms.addRecord(data, 0, data.length);
        } catch (RecordStoreException rse) {
            rse.printStackTrace();
        }
    }

    public void close() {
        try {
            rms.closeRecordStore();
        } catch (RecordStoreException rse) {
            //rse.printStackTrace();
        }
    }
}
